export interface RouteModel {
    path: string;
    component: any;
    title?: string;
    name?: string;
    className?: string;
    children?: RouteModel[];
    url?: string;
    icon?: string;
}

export abstract class ViewBaseService {
    abstract components: Array<any>
    abstract route: RouteModel | null;
    forRoot() {
        function traverse(data) {
            let arr = [];
            arr.push(data.component);
            for (let key in data) {
                if (Array.isArray(data[key])) {
                    data[key].forEach(v => {
                        arr = arr.concat(traverse(v))
                    })
                }
            }
            return arr;
        }
        let components = traverse(this.route || []);
        return components.concat(this.components);
    }

    getPathByComponentName(name?) {
        if (!name || this.route.name == name) {
            return this.route.path;
        }
        return this.route.children.find(x => x.name == name).path;
    }
}